﻿@{
    Layout = "../Shared/_Default.cshtml";
    var t_post = (Model.Post.Translations as IEnumerable<dynamic>)
        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
            JDM.Int32(Svc.Localization.Language.EntityID));
    ViewBag.PageTitle = T(Res.Name("Title"), t_post != null ? JDM.String(t_post.Title) : String.Empty);
    ViewBag.PageHistory = true;
}

@section Breadcrumb
{
    <span class="separator">/</span>
    <a href="@Url.Action(Loc.Act("Index").Set(new
    {
        id = JDM.Int32(Model.Author.EntityID)
    }).Localized())">@T(Res.Name("Blog"), JDM.String(Model.Author.Account.Username))</a>
}
@section Toolbar
{
    <span>@Svc.DateTimeRel((DateTime)JDM.DateTime(Model.Post.PublishedOn))</span>
     @if(JDM.HasFlags(Model.Post.Flags, "CommentAllowed") && 
        (Svc.IsAuthenticated || JDM.HasFlags(Model.Post.Flags, "AnonCommentAllowed")))
    {
        <span class="separator">&middot;</span>
        <a href="@Url.Action(Loc.Act("Comment").Ctrl("Feedback").Area("Wizard").Set(new
        {
            tgtType = "blogpost",
            tgtID = JDM.Int32(Model.Post.EntityID)
        }).Localized())">@T(Res.Name("Comment"))</a>
    }
    @if(Svc.IsAuthenticated && 
        Svc.PublicationAuthor != null && 
        JDM.Int32(Model.Author.EntityID) == JDM.Int32(Svc.PublicationAuthor.EntityID))
    {
        <span class="separator">&middot;</span>
        <a href="@Url.Action(Loc.Act("Edit").Ctrl("BlogPost").Area("Wizard").Set(new
        {
            id = JDM.Int32(Model.Post.EntityID)
        }).Localized())">@T(Res.Name("Edit"))</a>
    }
}
@section Sidebar
{
    @{
        Html.RenderAction(Loc.Act("_Overview").Ctrl("Account").NoArea().Set(new
        {
            id = JDM.Int32(Model.Author.EntityID)
        }).Localized());
        if(JDM.HasFlags(Model.Post.Flags, "RatingAllowed"))
        {
            <div class="box">
                <section>
                @{
                    Html.RenderPartial("_Rating", (object)Model.Post);
                }
                </section>
            </div>
        }
        if(Model.Post.FileGroup != null)
        {
            <div class="box">
                <header>
                    <h3>@T(Res.Name("Attachments"))</h3>
                </header>
                <section>
                    @{
                        Html.RenderAction(Loc.Act("_Attachments").Ctrl("Media").NoArea().Set(new
                        {
                            groupID = JDM.Int32(Model.Post.FileGroup.EntityID)
                        }).Localized());
                    }
                </section>
            </div>
        }
    }
}
<div class="box @(JDM.HasFlags(Model.Post.Flags, "Active") ? String.Empty : "draft")">
    <section>
    @{
        if((Model.Post.Attributes as IEnumerable<dynamic>).Any())
        {
            Html.RenderPartial("_Attributes", (object)Model.Post.Attributes);
        }
        Html.RenderPartial("_Text", (object)Model.Post);
    }
    </section>
    <footer>
        <nav>
        @{
            var tmp = Model.Post.Tags as IEnumerable<dynamic>;
            if(tmp.Any())
            {
                int n = 0;
                <span>@T(Res.Name("Tags"))</span>
                <ul class="bar">
                @foreach(var i in tmp)
                {
                    var t_tag = (i.Translations as IEnumerable<dynamic>)
                        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                            JDM.Int32(Svc.Localization.Language.EntityID));
                    <li><a href="@Url.Action(Loc.Act("Index").Set(new
                    {
                        tagID = JDM.Int32(i.EntityID)
                    }).Localized())">@(t_tag != null ? JDM.String(t_tag.Name) : JDM.String(i.EntityID))</a></li>
                    if(n < tmp.Count() - 1)
                    {
                        <li>,</li>
                    }
                    n++;
                }
                </ul>
            }
        }
        </nav>
    </footer>
</div>
@if(JDM.HasFlags(Model.Post.Flags, "CommentAllowed"))
{
    <div class="box">
        <header>
            <h3>@T(Res.Name("Comments"), JDM.Int32(Model.Post.CommentCount))</h3>
        </header>
        <section>
        @{
            Html.RenderAction(Loc.Act("_Comments").Set(new
            {
                id = JDM.Int32(Model.Post.EntityID)
            }).Localized());
        }
        </section>
    </div>
}
